class Validate {
  show() {
    console.log(this)
  }
  
  query(name) {
    return document.querySelector(name)
  }

  //10 次机会  9 
  confirm(password, confirmPassword, message, errorEl, eventType) {
    let elements = document.querySelectorAll(`[name='${password}'],[name='${confirmPassword}']`)
    elements.forEach( (elem)=> {
      elem.addEventListener(eventType,  ()=> {
        let passwordValue = this.query(`[name='${password}']`).value
        let confirmPasswordValue = this.query(`[name='${confirmPassword}']`).value
        //密码比对失败
        if (passwordValue != confirmPasswordValue) {
          this.query(errorEl).innerHTML = message
        } else {
          this.query(errorEl).innerHTML = ''
        }
      })
    })
  }

  max(el, message, len, errorEl, eventType) {
    const span = this.query(errorEl)
    this.query(`[name='${el}']`).addEventListener(eventType, function () {
      if (this.value.length > len) {
        span.innerHTML = message
      } else {
        span.innerHTML = ''
      }
    })
  }
  email() {}
  number() {}
  phone() {}
}
